package com.bwf.date;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/13 14:31
 * @Copyright 博为峰
 */
public class CalendarDemo {
    public static void main(String[] args) {
//        m1();
//        m2();
//        m3();
        //Date-->Calendar
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        //Calendar-->Date
        Date time = calendar.getTime();
    }

    private static void m3() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.YEAR, -1);
        int year = calendar.get(Calendar.YEAR);
        System.out.println("year = " + year);
    }

    private static void m2() {
        Calendar calendar = Calendar.getInstance();
//        calendar.set(Calendar.YEAR, 2008);
        calendar.set(2008, 7, 8);
    }

    private static void m1() {
        //Calendar calendar = new GregorianCalendar();
        //工厂方法
        Calendar calendar = Calendar.getInstance();
//        System.out.println("calendar = " + calendar);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;//从0开始
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int hour = calendar.get(Calendar.HOUR);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        System.out.println(year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second);
    }
}
